﻿#include "StartDialog.h"
#include "ui_StartDialog.h"
#include <QFileDialog>
#include <QMessageBox>

namespace MainWidget
{
	StartDialog::StartDialog(QWidget *parent)
		: QDialog(parent), ui(new Ui::StartDialog)
	{
		ui->setupUi(this);
		setWindowFlags(Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint);
	}

	StartDialog::~StartDialog()
	{
		delete ui;
	}

	QString StartDialog::getProjectFolder() const
	{
		return m_ProjectFolder;
	}

	void StartDialog::on_pb_NewProject_clicked()
	{
		QString dir = QFileDialog::getExistingDirectory(this, tr("Select a folder"), QCoreApplication::applicationDirPath() + "/../temp", QFileDialog::ShowDirsOnly);
		if (dir.isNull() || dir.isEmpty())
		{
			return;
		}
		QDir projectDir(dir);
		if (!projectDir.isEmpty())
		{
			QMessageBox::critical(this, tr("Error Info"), tr("Please select a empty folder!"));
			return;
		}
		m_ProjectFolder = dir;
		QDialog::accept();
	}

	void StartDialog::on_pb_OpenProject_clicked()
	{

		QString file = QFileDialog::getOpenFileName(this, tr("Select project file"), QCoreApplication::applicationDirPath(), tr("C3fd Project (*.c3fd)"));
		if (file.isNull() || file.isEmpty())
		{
			return;
		}
		QFileInfo fileInfo(file);
		QDir projectDir(fileInfo.absolutePath());
		/* 需要校验算例文件夹？？ */
		m_ProjectFolder = fileInfo.absolutePath();
		QDialog::accept();
	}

}